const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

// path.resolve() /User/chris/Downloads/demo
// path.join(__dirname, './dist') /User/chris/Downloads/demo/dist

const config = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js', // 合并js 减少请求 压缩文件
    path: path.join(__dirname, './dist')
  },
  module: {
    rules: [
      {
        test: /\.(css|scss|sass)$/,
        use: ['style-loader', 'css-loader', 'sass-loader'], // 从后往前解析
      },
      {
        test: /\.js$/,
        loader: 'babel-loader'
      }
    ]
  },
  devServer: {
    contentBase: './dist',
    hot: true
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new CleanWebpackPlugin()
  ]
}

module.exports = config



